<!DOCTYPE html>
<html lang="zh-CN">
<head>
  <meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=2">
<meta name="theme-color" content="#222">
<meta name="generator" content="Hexo 4.2.1">
  <link rel="apple-touch-icon" sizes="180x180" href="/images/apple-touch-icon.png">
  <link rel="icon" type="image/png" sizes="32x32" href="/images/favicon-32x32.png">
  <link rel="icon" type="image/png" sizes="16x16" href="/images/favicon-16x16.png">
  <link rel="mask-icon" href="/images/logo.svg" color="#222">
  <meta name="baidu-site-verification" content="WTTWi2XnJ5">

<link rel="stylesheet" href="/css/main.css">

<link rel="stylesheet" href="//fonts.googleapis.com/css?family=Josefin Sans:300,300italic,400,400italic,700,700italic|Lobster:300,300italic,400,400italic,700,700italic&display=swap&subset=latin,latin-ext">
<link rel="stylesheet" href="/lib/font-awesome/css/font-awesome.min.css">
  <link rel="stylesheet" href="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.css">

<script id="hexo-configurations">
    var NexT = window.NexT || {};
    var CONFIG = {"hostname":"lclong.top","root":"/","scheme":"Gemini","version":"7.7.1","exturl":true,"sidebar":{"position":"left","display":"post","padding":20,"offset":12,"onmobile":false},"copycode":{"enable":true,"show_result":true,"style":"mac"},"back2top":{"enable":true,"sidebar":true,"scrollpercent":true},"bookmark":{"enable":false,"color":"#222","save":"auto"},"fancybox":true,"mediumzoom":false,"lazyload":false,"pangu":false,"comments":{"style":"tabs","active":null,"storage":true,"lazyload":false,"nav":null},"algolia":{"hits":{"per_page":10},"labels":{"input_placeholder":"Search for Posts","hits_empty":"We didn't find any results for the search: ${query}","hits_stats":"${hits} results found in ${time} ms"}},"localsearch":{"enable":true,"trigger":"auto","top_n_per_article":1,"unescape":false,"preload":false},"motion":{"enable":true,"async":true,"transition":{"post_block":"fadeIn","post_header":"slideDownIn","post_body":"slideDownIn","coll_header":"slideLeftIn","sidebar":"slideUpIn"}},"path":"search.xml"};
  </script>

  <meta name="description" content="作为一个做 SPA 起家的框架，Vue 的开发学习曲线较为平缓，相对来说，开发体验属于上乘。但不少初学者会发现，自己的站点，随随便便打包文件就有 10M ！难以置信，其实这跟 Vue 的性能没有太大关系，我们可以通过配置文件来大大改善这一情况。 减少打包后文件体积的方法：  采用懒加载 启用 Gzip 压缩 将依赖库挂到 CDN 上 减少不必要的库依赖">
<meta property="og:type" content="article">
<meta property="og:title" content="(转)vue打包压缩体积">
<meta property="og:url" content="https://lclong.top/2018/09/13/(%E8%BD%AC)vue%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E4%BD%93%E7%A7%AF/index.html">
<meta property="og:site_name" content="Zlatanlong&#39;s T-blog">
<meta property="og:description" content="作为一个做 SPA 起家的框架，Vue 的开发学习曲线较为平缓，相对来说，开发体验属于上乘。但不少初学者会发现，自己的站点，随随便便打包文件就有 10M ！难以置信，其实这跟 Vue 的性能没有太大关系，我们可以通过配置文件来大大改善这一情况。 减少打包后文件体积的方法：  采用懒加载 启用 Gzip 压缩 将依赖库挂到 CDN 上 减少不必要的库依赖">
<meta property="og:locale" content="zh_CN">
<meta property="article:published_time" content="2018-09-13T10:53:12.000Z">
<meta property="article:modified_time" content="2018-09-13T10:53:12.000Z">
<meta property="article:author" content="Zlatanlong">
<meta property="article:tag" content="体积优化">
<meta property="article:tag" content="Vue.js">
<meta name="twitter:card" content="summary">

<link rel="canonical" href="https://lclong.top/2018/09/13/(%E8%BD%AC)vue%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E4%BD%93%E7%A7%AF/">


<script id="page-configurations">
  // https://hexo.io/docs/variables.html
  CONFIG.page = {
    sidebar: "",
    isHome: false,
    isPost: true
  };
</script>

  <title>(转)vue打包压缩体积 | Zlatanlong's T-blog</title>
  






  <noscript>
  <style>
  .use-motion .brand,
  .use-motion .menu-item,
  .sidebar-inner,
  .use-motion .post-block,
  .use-motion .pagination,
  .use-motion .comments,
  .use-motion .post-header,
  .use-motion .post-body,
  .use-motion .collection-header { opacity: initial; }

  .use-motion .site-title,
  .use-motion .site-subtitle {
    opacity: initial;
    top: initial;
  }

  .use-motion .logo-line-before i { left: initial; }
  .use-motion .logo-line-after i { right: initial; }
  </style>
</noscript>

</head>

<body itemscope itemtype="http://schema.org/WebPage">
  <div class="container use-motion">
    <div class="headband"></div>

    <header class="header" itemscope itemtype="http://schema.org/WPHeader">
      <div class="header-inner"><div class="site-brand-container">
  <div class="site-nav-toggle">
    <div class="toggle" aria-label="切换导航栏">
      <span class="toggle-line toggle-line-first"></span>
      <span class="toggle-line toggle-line-middle"></span>
      <span class="toggle-line toggle-line-last"></span>
    </div>
  </div>

  <div class="site-meta">

    <div>
      <a href="/" class="brand" rel="start">
        <span class="logo-line-before"><i></i></span>
        <span class="site-title">Zlatanlong's T-blog</span>
        <span class="logo-line-after"><i></i></span>
      </a>
    </div>
        <h1 class="site-subtitle" itemprop="description">Lakers is Championship!</h1>
      
  </div>

  <div class="site-nav-right"></div>
</div>


<nav class="site-nav">
  
  <ul id="menu" class="menu">
        <li class="menu-item menu-item-home">

    <a href="/" rel="section"><i class="fa fa-fw fa-home"></i>首页</a>

  </li>
        <li class="menu-item menu-item-tags">

    <a href="/tags/" rel="section"><i class="fa fa-fw fa-tags"></i>标签<span class="badge">31</span></a>

  </li>
        <li class="menu-item menu-item-categories">

    <a href="/categories/" rel="section"><i class="fa fa-fw fa-th"></i>分类<span class="badge">23</span></a>

  </li>
        <li class="menu-item menu-item-archives">

    <a href="/archives/" rel="section"><i class="fa fa-fw fa-archive"></i>归档<span class="badge">38</span></a>

  </li>
        <li class="menu-item menu-item-aboutme">

    <a href="/aboutme/" rel="section"><i class="fa fa-fw fa-user"></i>博主</a>

  </li>
      <li class="menu-item menu-item-search">
        <a role="button" class="popup-trigger"><i class="fa fa-search fa-fw"></i>搜索
        </a>
      </li>
  </ul>

</nav>
  <div class="site-search">
    <div class="popup search-popup">
    <div class="search-header">
  <span class="search-icon">
    <i class="fa fa-search"></i>
  </span>
  <div class="search-input-container">
    <input autocomplete="off" autocorrect="off" autocapitalize="off"
           placeholder="搜索..." spellcheck="false"
           type="search" class="search-input">
  </div>
  <span class="popup-btn-close">
    <i class="fa fa-times-circle"></i>
  </span>
</div>
<div id="search-result"></div>

</div>
<div class="search-pop-overlay"></div>

  </div>
</div>
    </header>

    
  <div class="reading-progress-bar"></div>


    <main class="main">
      <div class="main-inner">
        <div class="content-wrap">
          

          <div class="content">
            

  <div class="posts-expand">
    
  
  
  <article itemscope itemtype="http://schema.org/Article" class="post-block " lang="zh-CN">
    <link itemprop="mainEntityOfPage" href="https://lclong.top/2018/09/13/(%E8%BD%AC)vue%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E4%BD%93%E7%A7%AF/">

    <span hidden itemprop="author" itemscope itemtype="http://schema.org/Person">
      <meta itemprop="image" content="/images/avatar.jpg">
      <meta itemprop="name" content="Zlatanlong">
      <meta itemprop="description" content="生活就像巧克力🍫">
    </span>

    <span hidden itemprop="publisher" itemscope itemtype="http://schema.org/Organization">
      <meta itemprop="name" content="Zlatanlong's T-blog">
    </span>
      <header class="post-header">
        <h2 class="post-title" itemprop="name headline">
          (转)vue打包压缩体积
        </h2>

        <div class="post-meta">
          
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-calendar-o"></i>
              </span>
              <span class="post-meta-item-text">发表于</span>

              <time title="创建时间：2018-09-13 18:53:12" itemprop="dateCreated datePublished" datetime="2018-09-13T18:53:12+08:00">2018-09-13</time>
            </span>
            <span class="post-meta-item">
              <span class="post-meta-item-icon">
                <i class="fa fa-folder-o"></i>
              </span>
              <span class="post-meta-item-text">分类于</span>
                <span itemprop="about" itemscope itemtype="http://schema.org/Thing">
                  <a href="/categories/Vue-js/" itemprop="url" rel="index">
                    <span itemprop="name">Vue.js</span>
                  </a>
                </span>
            </span>

          
            <span id="/2018/09/13/(%E8%BD%AC)vue%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E4%BD%93%E7%A7%AF/" class="post-meta-item leancloud_visitors" data-flag-title="(转)vue打包压缩体积" title="阅读次数">
              <span class="post-meta-item-icon">
                <i class="fa fa-eye"></i>
              </span>
              <span class="post-meta-item-text">阅读次数：</span>
              <span class="leancloud-visitors-count"></span>
            </span>
  
  <span class="post-meta-item">
    
      <span class="post-meta-item-icon">
        <i class="fa fa-comment-o"></i>
      </span>
      <span class="post-meta-item-text">评论次数：</span>
    
    <a title="valine" href="/2018/09/13/(%E8%BD%AC)vue%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E4%BD%93%E7%A7%AF/#valine-comments" itemprop="discussionUrl">
      <span class="post-comments-count valine-comment-count" data-xid="/2018/09/13/(%E8%BD%AC)vue%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E4%BD%93%E7%A7%AF/" itemprop="commentCount"></span>
    </a>
  </span>
  
  <br>
            <span class="post-meta-item" title="本文字数">
              <span class="post-meta-item-icon">
                <i class="fa fa-file-word-o"></i>
              </span>
                <span class="post-meta-item-text">本文字数：</span>
              <span>2.8k</span>
            </span>
            <span class="post-meta-item" title="阅读时长">
              <span class="post-meta-item-icon">
                <i class="fa fa-clock-o"></i>
              </span>
                <span class="post-meta-item-text">阅读时长 &asymp;</span>
              <span>7 分钟</span>
            </span>

        </div>
      </header>

    
    
    
    <div class="post-body" itemprop="articleBody">

      
        <p>作为一个做 SPA 起家的框架，Vue 的开发学习曲线较为平缓，相对来说，开发体验属于上乘。但不少初学者会发现，自己的站点，随随便便打包文件就有 10M ！难以置信，其实这跟 Vue 的性能没有太大关系，我们可以通过配置文件来大大改善这一情况。</p>
<p>减少打包后文件体积的方法：</p>
<ol>
<li>采用懒加载</li>
<li>启用 Gzip 压缩</li>
<li>将依赖库挂到 CDN 上</li>
<li>减少不必要的库依赖</li>
</ol>
<a id="more"></a>

<h2 id="准备知识："><a href="#准备知识：" class="headerlink" title="准备知识："></a>准备知识：</h2><blockquote>
<ol>
<li>如何用 vue-cli 创建 Vue 应用，并对其有一定了解，否则，请移步<span class="exturl" data-url="aHR0cHM6Ly9jbi52dWVqcy5vcmcvdjIvZ3VpZGUvaW5zdGFuY2UuaHRtbA==" title="https://cn.vuejs.org/v2/guide/instance.html">官网<i class="fa fa-external-link"></i></span></li>
<li>对 Webpack 有了解，知道它是一个打包工具，并且它的四大要素：entity、output、。进一步理解 webpack，移步<span class="exturl" data-url="aHR0cHM6Ly93ZWJwYWNrLmpzLm9yZy8=" title="https://webpack.js.org/">这里<i class="fa fa-external-link"></i></span></li>
</ol>
</blockquote>
<h3 id="懒加载"><a href="#懒加载" class="headerlink" title="懒加载"></a>懒加载</h3><p>官网上对懒加载的解释是这样的：</p>
<blockquote>
<p>当打包构建应用时，Javascript 包会变得非常大，影响页面加载。如果我们能把不同路由对应的组件分割成不同的代码块，然后当路由被访问的时候才加载对应组件，这样就更加高效了。</p>
<p>结合 Vue 的异步组件和 Webpack 的代码分割功能，轻松实现路由组件的懒加载。</p>
</blockquote>
<p>它的作用是实现延迟加载，避免一次性加载过大的文件，增加首页渲染时间，影响用户体验。</p>
<h4 id="如何实现？"><a href="#如何实现？" class="headerlink" title="如何实现？"></a>如何实现？</h4><p>要实现懒加载很简单，我们只需要改变组件的导入方式：</p>
<p><strong>before:</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">import Article from &#39;@&#x2F;components&#x2F;Article&#39;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p><strong>after:</strong></p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br></pre></td><td class="code"><pre><span class="line">const Article &#x3D; () &#x3D;&gt; import(&#39;@&#x2F;components&#x2F;Article&#39;)</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<h4 id="原理是什么？"><a href="#原理是什么？" class="headerlink" title="原理是什么？"></a>原理是什么？</h4><p>本质上，它是利用了 Promise，具体请见：<span class="exturl" data-url="aHR0cHM6Ly9jbi52dWVqcy5vcmcvdjIvZ3VpZGUvY29tcG9uZW50cy5odG1sIyVFNSVCQyU4MiVFNiVBRCVBNSVFNyVCQiU4NCVFNCVCQiVCNg==" title="https://cn.vuejs.org/v2/guide/components.html#%E5%BC%82%E6%AD%A5%E7%BB%84%E4%BB%B6">异步组件<i class="fa fa-external-link"></i></span></p>
<h3 id="启用-Gzip-压缩"><a href="#启用-Gzip-压缩" class="headerlink" title="启用 Gzip 压缩"></a>启用 Gzip 压缩</h3><p>vue 默认不启用 Gzip 压缩，但我们知道，压缩后的文件体积会大大减少，这适用于线上部署。 如何启用也很简单： 首先，在 <code>config</code> 中将 <code>build.productionGzip</code> 设置为 <code>true</code> 然后，确认 <code>webpack.prod.conf.js</code> 中有如下代码：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br><span class="line">15</span><br><span class="line">16</span><br><span class="line">17</span><br><span class="line">18</span><br></pre></td><td class="code"><pre><span class="line">if (config.build.productionGzip) &#123;</span><br><span class="line">  const CompressionWebpackPlugin &#x3D; require(&#39;compression-webpack-plugin&#39;)</span><br><span class="line"></span><br><span class="line">  webpackConfig.plugins.push(</span><br><span class="line">    new CompressionWebpackPlugin(&#123;</span><br><span class="line">      asset: &#39;[path].gz[query]&#39;,</span><br><span class="line">      algorithm: &#39;gzip&#39;,</span><br><span class="line">      test: new RegExp(</span><br><span class="line">        &#39;\\.(&#39; +</span><br><span class="line">        config.build.productionGzipExtensions.join(&#39;|&#39;) +</span><br><span class="line">        &#39;)$&#39;</span><br><span class="line">      ),</span><br><span class="line">      threshold: 10240,</span><br><span class="line">      minRatio: 0.8</span><br><span class="line">    &#125;)</span><br><span class="line">  )</span><br><span class="line">&#125;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>如果有的话，下面只要使用 <code>npm install --save-dev compression-webpack-plugin</code> 安装 webpack 插件，这样，你在 build 项目时，webpack 会帮你压缩文件。 如果没有的话，你只要把上面代码复制到 webpack 配置文件的 <code>plugins</code> 下即可。 如何方面查看build之后的文件大小呢？我们可以使用另外一个 webpack 插件：<code>webpack-bundle-analyzer</code> ，如何使用呢？默认 Vue 会导入这个插件，我们只需要调用即可：在 <code>package.json</code> 文件中增加以下命令：<code>&quot;analyzer&quot;: &quot;NODE_ENV=production npm_config_report=true npm run build&quot;</code>，运行 <code>npm run analyzer</code> ，等待一会，就可以看到整个项目的打包情况了。</p>
<h3 id="将依赖库挂到-CDN-上"><a href="#将依赖库挂到-CDN-上" class="headerlink" title="将依赖库挂到 CDN 上"></a>将依赖库挂到 CDN 上</h3><p>如果你对首屏响应速度要求比较高，那么，CDN 也不失为一种好方法。 它的原理是将一些依赖库挂载到 CDN 上，通过在 html 文件 <code>script</code> 便签引入的方式进行加载，减少的打包文件，从而缩小了体积。</p>
<p>以 element 为例：</p>
<p>首先，在 html 中引入库：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br><span class="line">7</span><br><span class="line">8</span><br><span class="line">9</span><br><span class="line">10</span><br><span class="line">11</span><br><span class="line">12</span><br><span class="line">13</span><br><span class="line">14</span><br></pre></td><td class="code"><pre><span class="line">&lt;!DOCTYPE html&gt;</span><br><span class="line">&lt;html&gt;</span><br><span class="line">  &lt;head&gt;</span><br><span class="line">    &lt;meta charset&#x3D;&quot;utf-8&quot;&gt;</span><br><span class="line">    &lt;title&gt;demo-vue-project&lt;&#x2F;title&gt;</span><br><span class="line">    &lt;link rel&#x3D;&quot;stylesheet&quot; href&#x3D;&quot;https:&#x2F;&#x2F;cdn.bootcss.com&#x2F;element-ui&#x2F;2.0.8&#x2F;theme-chalk&#x2F;index.css&quot;&gt;</span><br><span class="line">  &lt;&#x2F;head&gt;</span><br><span class="line">  &lt;body&gt;</span><br><span class="line">    &lt;div id&#x3D;&quot;app&quot;&gt;&lt;&#x2F;div&gt;</span><br><span class="line">    &lt;!-- built files will be auto injected --&gt;</span><br><span class="line">    &lt;script src&#x3D;&quot;https:&#x2F;&#x2F;cdn.bootcss.com&#x2F;element-ui&#x2F;2.0.7&#x2F;index.js&quot;&gt;&lt;&#x2F;script&gt;</span><br><span class="line">  &lt;&#x2F;body&gt;</span><br><span class="line">&lt;&#x2F;html&gt;</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>然后在 <code>webpack.base.conf.js</code> 中移除对这三个库的依赖：</p>
<figure class="highlight plain"><table><tr><td class="gutter"><pre><span class="line">1</span><br><span class="line">2</span><br><span class="line">3</span><br><span class="line">4</span><br><span class="line">5</span><br><span class="line">6</span><br></pre></td><td class="code"><pre><span class="line">externals: &#123;</span><br><span class="line">    &#39;vue&#39;: &#39;Vue&#39;,</span><br><span class="line">    &#39;vue-router&#39;: &#39;VueRouter&#39;,</span><br><span class="line">    &#39;element-ui&#39;: &#39;ELEMENT&#39;</span><br><span class="line">  &#125;,</span><br><span class="line">复制代码</span><br></pre></td></tr></table></figure>

<p>这样我们就可以愉快地享受 CDN 了。</p>
<h3 id="减少不必要的库依赖"><a href="#减少不必要的库依赖" class="headerlink" title="减少不必要的库依赖"></a>减少不必要的库依赖</h3><p>这一点就是见仁见智了。如果你使用了上面提到的 <code>webpack-bundle-analyzer</code> ，你会发现占用你的包的大部分是你引用的一些库，诸如：Element-ui、lodash、highlight 等等。不知道你们看到是什么心情，反正我都想删掉它们，自己写需要的功能了，毕竟我只需要它们其中的一小部分功能，却牺牲了大量的带宽！</p>
<h2 id="写在最后"><a href="#写在最后" class="headerlink" title="写在最后"></a>写在最后</h2><p>webpack 是一个强大的打包工具，这篇文章写于 V3.4 的时候，现在 V4 已经出来了，配置文件更加地简单，值得一看！本文写得粗糙，如果不对之处，欢迎批评指正！</p>
<blockquote>
<p> 作者：allenWang</p>
<p> 链接：<span class="exturl" data-url="aHR0cHM6Ly9qdWVqaW4uaW0vcG9zdC81YWJiYTY4Y2YyNjVkYTIzOWM3YjZiZGM=" title="https://juejin.im/post/5abba68cf265da239c7b6bdc">https://juejin.im/post/5abba68cf265da239c7b6bdc<i class="fa fa-external-link"></i></span></p>
<p> 来源：掘金</p>
</blockquote>

    </div>

    
    
    
      
  <div class="popular-posts-header">相关文章</div>
  <ul class="popular-posts">
    <li class="popular-posts-item">
      <div class="popular-posts-title"><a href="\2018\08\20\(转)Vue单页应用的首屏优化\" rel="bookmark">(转)vue+axios上传文件</a></div>
    </li>
  </ul>

        

<div>
<ul class="post-copyright">
  <li class="post-copyright-author">
    <strong>本文作者： </strong>Zlatanlong
  </li>
  <li class="post-copyright-link">
    <strong>本文链接：</strong>
    <a href="https://lclong.top/2018/09/13/(%E8%BD%AC)vue%E6%89%93%E5%8C%85%E5%8E%8B%E7%BC%A9%E4%BD%93%E7%A7%AF/" title="(转)vue打包压缩体积">https://lclong.top/2018/09/13/(转)vue打包压缩体积/</a>
  </li>
  <li class="post-copyright-license">
    <strong>版权声明： </strong>本博客所有文章除特别声明外，均采用 <span class="exturl" data-url="aHR0cHM6Ly9jcmVhdGl2ZWNvbW1vbnMub3JnL2xpY2Vuc2VzL2J5LW5jLXNhLzQuMC96aC1DTg=="><i class="fa fa-fw fa-creative-commons"></i>BY-NC-SA</span> 许可协议。转载请注明出处！
  </li>
</ul>
</div>


      <footer class="post-footer">
          
          <div class="post-tags">
              <a href="/tags/%E4%BD%93%E7%A7%AF%E4%BC%98%E5%8C%96/" rel="tag"><i class="fa fa-tag"></i> 体积优化</a>
              <a href="/tags/Vue-js/" rel="tag"><i class="fa fa-tag"></i> Vue.js</a>
          </div>

        


        
    <div class="post-nav">
      <div class="post-nav-item">
    <a href="/2018/09/04/springboot/web%E7%AC%94%E8%AE%B0/(%E8%BD%AC)%E6%B3%A8%E8%A7%A3-CrossOrigin%E8%A7%A3%E5%86%B3%E8%B7%A8%E5%9F%9F%E9%97%AE%E9%A2%98/" rel="prev" title="(转)注解@CrossOrigin解决跨域问题">
      <i class="fa fa-chevron-left"></i> (转)注解@CrossOrigin解决跨域问题
    </a></div>
      <div class="post-nav-item">
    <a href="/2018/09/30/(%E8%BD%AC)ThreadLocal%E5%8E%9F%E7%90%86/" rel="next" title="(转)ThreadLocal原理">
      (转)ThreadLocal原理 <i class="fa fa-chevron-right"></i>
    </a></div>
    </div>
      </footer>
    
  </article>
  
  
  
  </div>


          </div>
          
    <div class="comments" id="valine-comments"></div>

<script>
  window.addEventListener('tabs:register', () => {
    let activeClass = CONFIG.comments.activeClass;
    if (CONFIG.comments.storage) {
      activeClass = localStorage.getItem('comments_active') || activeClass;
    }
    if (activeClass) {
      let activeTab = document.querySelector(`a[href="#comment-${activeClass}"]`);
      if (activeTab) {
        activeTab.click();
      }
    }
  });
  if (CONFIG.comments.storage) {
    window.addEventListener('tabs:click', event => {
      if (!event.target.matches('.tabs-comment .tab-content .tab-pane')) return;
      let commentClass = event.target.classList[1];
      localStorage.setItem('comments_active', commentClass);
    });
  }
</script>

        </div>
          
  
  <div class="toggle sidebar-toggle">
    <span class="toggle-line toggle-line-first"></span>
    <span class="toggle-line toggle-line-middle"></span>
    <span class="toggle-line toggle-line-last"></span>
  </div>

  <aside class="sidebar">
    <div class="sidebar-inner">

      <ul class="sidebar-nav motion-element">
        <li class="sidebar-nav-toc">
          文章目录
        </li>
        <li class="sidebar-nav-overview">
          站点概览
        </li>
      </ul>

      <!--noindex-->
      <div class="post-toc-wrap sidebar-panel">
          <div class="post-toc motion-element"><ol class="nav"><li class="nav-item nav-level-2"><a class="nav-link" href="#准备知识："><span class="nav-number">1.</span> <span class="nav-text">准备知识：</span></a><ol class="nav-child"><li class="nav-item nav-level-3"><a class="nav-link" href="#懒加载"><span class="nav-number">1.1.</span> <span class="nav-text">懒加载</span></a><ol class="nav-child"><li class="nav-item nav-level-4"><a class="nav-link" href="#如何实现？"><span class="nav-number">1.1.1.</span> <span class="nav-text">如何实现？</span></a></li><li class="nav-item nav-level-4"><a class="nav-link" href="#原理是什么？"><span class="nav-number">1.1.2.</span> <span class="nav-text">原理是什么？</span></a></li></ol></li><li class="nav-item nav-level-3"><a class="nav-link" href="#启用-Gzip-压缩"><span class="nav-number">1.2.</span> <span class="nav-text">启用 Gzip 压缩</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#将依赖库挂到-CDN-上"><span class="nav-number">1.3.</span> <span class="nav-text">将依赖库挂到 CDN 上</span></a></li><li class="nav-item nav-level-3"><a class="nav-link" href="#减少不必要的库依赖"><span class="nav-number">1.4.</span> <span class="nav-text">减少不必要的库依赖</span></a></li></ol></li><li class="nav-item nav-level-2"><a class="nav-link" href="#写在最后"><span class="nav-number">2.</span> <span class="nav-text">写在最后</span></a></li></ol></div>
      </div>
      <!--/noindex-->

      <div class="site-overview-wrap sidebar-panel">
        <div class="site-author motion-element" itemprop="author" itemscope itemtype="http://schema.org/Person">
    <img class="site-author-image" itemprop="image" alt="Zlatanlong"
      src="/images/avatar.jpg">
  <p class="site-author-name" itemprop="name">Zlatanlong</p>
  <div class="site-description" itemprop="description">生活就像巧克力🍫</div>
</div>
<div class="site-state-wrap motion-element">
  <nav class="site-state">
      <div class="site-state-item site-state-posts">
          <a href="/archives/">
        
          <span class="site-state-item-count">38</span>
          <span class="site-state-item-name">日志</span>
        </a>
      </div>
      <div class="site-state-item site-state-categories">
            <a href="/categories/">
          
        <span class="site-state-item-count">23</span>
        <span class="site-state-item-name">分类</span></a>
      </div>
      <div class="site-state-item site-state-tags">
            <a href="/tags/">
          
        <span class="site-state-item-count">31</span>
        <span class="site-state-item-name">标签</span></a>
      </div>
  </nav>
</div>
  <div class="links-of-author motion-element">
      <span class="links-of-author-item">
        <span class="exturl" data-url="aHR0cHM6Ly9naXRodWIuY29tL3psYXRhbmxvbmc=" title="GitHub → https:&#x2F;&#x2F;github.com&#x2F;zlatanlong"><i class="fa fa-fw fa-github"></i>GitHub</span>
      </span>
      <span class="links-of-author-item">
        <span class="exturl" data-url="bWFpbHRvOmxvbmctdHhnY0Bmb3htYWlsLmNvbQ==" title="E-Mail → mailto:long-txgc@foxmail.com"><i class="fa fa-fw fa-envelope"></i>E-Mail</span>
      </span>
  </div>


  <div class="links-of-blogroll motion-element">
    <div class="links-of-blogroll-title">
      <i class="fa fa-fw fa-link"></i>
      关注列表
    </div>
    <ul class="links-of-blogroll-list">
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9sZWZsYWNvbi5naXRodWIuaW8v" title="https:&#x2F;&#x2F;leflacon.github.io&#x2F;">leflacon</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cHM6Ly9ib2Jib3NzLmdpdGh1Yi5pby8=" title="https:&#x2F;&#x2F;bobboss.github.io&#x2F;">BobBoss</span>
        </li>
        <li class="links-of-blogroll-item">
          <span class="exturl" data-url="aHR0cDovL29wdGltaXN0aWNhdC54eXovdXNlcj91c2VySWQ9bHpkY2w=" title="http:&#x2F;&#x2F;optimisticat.xyz&#x2F;user?userId&#x3D;lzdcl">lzdcl</span>
        </li>
    </ul>
  </div>

      </div>
        <div class="back-to-top motion-element">
          <i class="fa fa-arrow-up"></i>
          <span>0%</span>
        </div>

    </div>
  </aside>
  <div id="sidebar-dimmer"></div>


      </div>
    </main>

    <footer class="footer">
      <div class="footer-inner">
        

<div class="copyright">
  
  &copy; 2018 – 
  <span itemprop="copyrightYear">2021</span>
  <span class="with-love">
    <i class="fa fa-heart"></i>
  </span>
  <span class="author" itemprop="copyrightHolder">Zlatanlong</span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item-icon">
      <i class="fa fa-area-chart"></i>
    </span>
      <span class="post-meta-item-text">站点总字数：</span>
    <span title="站点总字数">166k</span>
</div>
  <div class="powered-by">由 <span class="exturl theme-link" data-url="aHR0cHM6Ly9oZXhvLmlv">Hexo</span> 强力驱动 v4.2.1
  </div>
  <span class="post-meta-divider">|</span>
  <div class="theme-info">主题 – <span class="exturl theme-link" data-url="aHR0cHM6Ly90aGVtZS1uZXh0Lm9yZw==">NexT.Gemini</span> v7.7.1
  </div>

        
<div class="busuanzi-count">
  <script async src="https://busuanzi.ibruce.info/busuanzi/2.3/busuanzi.pure.mini.js"></script>
    <span class="post-meta-item" id="busuanzi_container_site_uv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-user"></i>
      </span>
      <span class="site-uv" title="总访客量">
        <span id="busuanzi_value_site_uv"></span>
      </span>
    </span>
    <span class="post-meta-divider">|</span>
    <span class="post-meta-item" id="busuanzi_container_site_pv" style="display: none;">
      <span class="post-meta-item-icon">
        <i class="fa fa-eye"></i>
      </span>
      <span class="site-pv" title="总访问量">
        <span id="busuanzi_value_site_pv"></span>
      </span>
    </span>
</div>








      </div>
    </footer>
  </div>

  
  <script color='0,0,255' opacity='0.5' zIndex='-1' count='99' src="//cdn.jsdelivr.net/gh/theme-next/theme-next-canvas-nest@latest/canvas-nest-nomobile.min.js"></script>
  <script src="/lib/anime.min.js"></script>
  <script src="//cdn.jsdelivr.net/npm/jquery@3/dist/jquery.min.js"></script>
  <script src="//cdn.jsdelivr.net/gh/fancyapps/fancybox@3/dist/jquery.fancybox.min.js"></script>
  <script src="/lib/velocity/velocity.min.js"></script>
  <script src="/lib/velocity/velocity.ui.min.js"></script>

<script src="/js/utils.js"></script>

<script src="/js/motion.js"></script>


<script src="/js/schemes/pisces.js"></script>


<script src="/js/next-boot.js"></script>




  
  <script>
    (function(){
      var bp = document.createElement('script');
      var curProtocol = window.location.protocol.split(':')[0];
      bp.src = (curProtocol === 'https') ? 'https://zz.bdstatic.com/linksubmit/push.js' : 'http://push.zhanzhang.baidu.com/push.js';
      var s = document.getElementsByTagName("script")[0];
      s.parentNode.insertBefore(bp, s);
    })();
  </script>




  
<script src="/js/local-search.js"></script>













  

  


<script>
NexT.utils.loadComments(document.querySelector('#valine-comments'), () => {
  NexT.utils.getScript('//unpkg.com/valine/dist/Valine.min.js', () => {
    var GUEST = ['nick', 'mail', 'link'];
    var guest = 'nick,mail,link';
    guest = guest.split(',').filter(item => {
      return GUEST.includes(item);
    });
    new Valine({
      el         : '#valine-comments',
      verify     : false,
      notify     : false,
      appId      : 'H5inyassVpcpItLTuMJH9aBg-gzGzoHsz',
      appKey     : 'mBzB6QB3deD6zw8YEIKVQdzz',
      placeholder: "快来说两句吧。。。",
      avatar     : 'mm',
      meta       : guest,
      pageSize   : '10' || 10,
      visitor    : true,
      lang       : 'zh-cn' || 'zh-cn',
      path       : location.pathname,
      recordIP   : false,
      serverURLs : ''
    });
  }, window.Valine);
});
</script>

</body>
</html>
